package com.example.app2024.handle;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.app2024.R;
import com.google.android.material.dialog.InsetDialogOnTouchListener;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.sql.Driver;
import java.util.Date;


public class HandleActivity extends AppCompatActivity
{


      private static final String TAG = "MainActivity";
      public static final int CODE = 10001;
      private TextView mTextview;


      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_handle);

            mTextview = findViewById(R.id.tvaaaaa);

            final Handler handler = new TestHandler(this);

            Message message = Message.obtain();
            message.arg1 = 10000;
            message.what = CODE;


            handler.sendMessageDelayed(message, 1000);
             LinearLayout aa =  (LinearLayout) LinearLayout.inflate(this, R.layout.tempaaa, null);


      }

      public static class TestHandler extends Handler{

            public final WeakReference<HandleActivity> mWeakReference;
            public TestHandler(HandleActivity activity) {
                  mWeakReference = new WeakReference<>(activity);
            }





            @Override
            public void handleMessage(Message msg) {
                  super.handleMessage(msg);
                  HandleActivity activity = mWeakReference.get();
                  if(msg.what == CODE){
                        int time = msg.arg1;
                        activity.mTextview.setText(String.valueOf(time/1000));
                        Message message = Message.obtain();
                        message.what = CODE;
                        message.arg1  = time - 1000;

                        if (time > 0) {
                              sendMessageDelayed(message, 1000);
                        }
                  }

            }
      }


}